package cn.wolfcode.rbac.web.controller;

import cn.wolfcode.rbac.domain.SystemDictionary;
import cn.wolfcode.rbac.domain.SystemDictionaryItem;
import cn.wolfcode.rbac.query.QueryObject;
import cn.wolfcode.rbac.query.SystemDictionaryItemQuery;
import cn.wolfcode.rbac.service.ISystemDictionaryItemService;
import cn.wolfcode.rbac.service.ISystemDictionaryService;
import cn.wolfcode.rbac.util.JsonResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/systemDictionaryItem")
public class SystemDictionaryItemController {
    @Autowired
    private ISystemDictionaryItemService systemDictionaryItemService;

    @Autowired
    private ISystemDictionaryService systemDictionaryService;

    @RequestMapping("/list")
    public String list(@ModelAttribute("qo") SystemDictionaryItemQuery qo, Model model){
        PageInfo pageInfo = this.systemDictionaryItemService.query(qo);
        model.addAttribute("result",pageInfo);
        model.addAttribute("systemDictionarys",systemDictionaryService.list());
        return "systemDictionaryItem/list";
    }

    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public JsonResult saveOrUpdate(SystemDictionaryItem entity){
        if(entity.getId()==null){
            this.systemDictionaryItemService.saveOrUpdate(entity);
        }else {
            this.systemDictionaryItemService.saveOrUpdate(entity);
        }
        return new JsonResult("操作成功",true);
    }

    @RequestMapping("delete")
    @ResponseBody
    public JsonResult delete(Long id){
            this.systemDictionaryItemService.delete(id);
        return new JsonResult(true);
    }
}
